<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>产品信息表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
    </div>
</script>
<script type="text/html" id="bar">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>



<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use('table', function() {
        var table = layui.table;
        table.render({
            elem: '#test',
            height: 800 ,
            url: '/pi/query' ,
            toolbar: '#toolbarDemo',
            title: '产品信息表',
            even: true,
            page: true,
            limit: 10,
            cols: [
                [{
                    type: 'checkbox',
                    fixed: 'left',
                    width: '3%'
                }, {
                    field: 'id', title: '产品编号', width: '7%', sort: true, fixed: 'left', templet: function (res) {
                        return res.pi.id;
                    }
                }
                    , {
                    field: 'name', title: '产品名', width: '10%', sort: true, templet: function (res) {
                        return res.pi.name;
                    }
                }
                    , {
                    field: 'product_specificationId', title: '规格编号', width: '10%', templet: function (res) {
                        return res.pi.product_specificationId;
                    }
                }
                    , {
                    field: 'price', title: '定价', width: '10%', templet: function (res) {
                        return res.pi.price;
                    }
                }
                    , {
                    field: 'time', title: '时间', width: '10%', sort: true, templet: function (res) {
                        return res.pi.time;
                    }
                }
                    , {
                    field: 'psName', title: '规格名', width: '10%', sort: true, templet: function (res) {
                        return res.ps.name;
                    }
                }
                    , {
                    field: 'chain_typeId', title: '速别编号', width: '10%', templet: function (res) {
                        return res.pi.chain_typeId;
                    }
                }
                    , {field: 'sectionNum', title: '节数', width: '10%', templet: function (res) {
                        return res.pi.sectionNum;
                    }
                }
                    , {field: 'summary', title: '备注', width: '10%', templet: function (res) {
                        return res.pi.summary == ""? "空":res.pi.summary;
                    }
                }
                    , {field: '', title: '操作', width: '10%', toolbar: '#bar'}
                    ]]
                ,parseData:function (res) {
                    return {
                        "count":res.count,
                        "msg":res.msg,
                        "data":res.data,
                        "code":res.code
                    }
                }
                ,request:{
                    pageName: "page",
                    limitName: "limit"
                }
        });
        layui.table.on('tool(test)', function(obj){
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var id = obj.data.pi.id;
            objdata1 = id;
            if(layEvent === 'detail'){
                toJumpGet($('.layui-body'),"/pages/pi/piUnique.html");
            } else if(layEvent === 'delete'){
                $.post(
                    "/pi/fakeDelete", {
                        id: id
                    },function (res) {
                        var code = res.code;
                        if (code == 0){
                            layer.alert(res.msg);
                            toJumpGet($('.layui-body'),"/pages/pi/piList.html");
                        }else {
                            layer.alert(res.msg);
                        }
                    }
                );
            }
        });
    });
</script>

</body>
</html>